package com.yoomiito.app.ui.order.sureorder

import android.text.TextUtils
import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.sdd.ShareMsg
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.showToast
import com.yoomiito.app.utils.YMToast

class BuySuccessPresenter(appConfig: AppConfig?) : BaseActPresenter<BuyResultActivity>(appConfig){

    /**
     * 爆品商品获取加脉码
     */
    fun getJiaMiaCode(orderId:String){
        YmApi.getYmService()
                .getJiaMaiCode(orderId)
                .compose(v?.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<List<String>>(){
                    override fun onSuccess(t: List<String>?) {
                        v?.dismissLoading()
                        v?.showData(t!!)
                    }

                    override fun onFail(error: ApiException?) {
                        v?.dismissLoading()
                        error?.msg?.showToast()
                    }

                })
    }

    /**
     * 送多多--获取分享信息
     * @param type
     * @param goodsId
     */
    fun getSddShareMsg(type: Int) {
        YmApi.getYmService()
                .shareMsg(type, "")
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<ShareMsg?>() {
                    override fun onSuccess(shareMsg: ShareMsg?) {
                        v.sddShareMsg(shareMsg)
                    }

                    override fun onFail(error: ApiException) {
                        v.dismissLoading()
                        if (!TextUtils.isEmpty(error.msg)) YMToast.showCenterToast(error.msg)
                    }
                })
    }
}